<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:cache="http://www.springframework.org/schema/cache"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	    http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.0.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
		http://www.springframework.org/schema/tx 
	    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring  
  		http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
  		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
  		http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache-4.0.xsd">


	<context:component-scan base-package="ipebg" />
	<import resource="classpath:spring/spring-redis.xml" />
	<import resource="classpath:spring/spring-mongo.xml" />
	<import resource="classpath:spring/spring-dubbo.xml" />
	<import resource="classpath:spring/spring-activemq.xml" />
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
			</list>
		</property>
		<property name="ignoreUnresolvablePlaceholders" value="true" />
	</bean>

	<!--數據庫連接池 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="properties">
			<bean class="ipebg.mzk.common.util.C3P0DatasourcePropertiesFactory" factory-method="getProperties">

				<constructor-arg type="java.lang.String">
					<value>${datasource.password.encrypted}</value>
				</constructor-arg>
			</bean>
		</property>
		<property name="driverClass">
			<value>${datasource.driverClassName}</value>
		</property>
		<property name="jdbcUrl">
			<value>${datasource.url}</value>
		</property>
		<property name="user">
			<value>${datasource.username}</value>
		</property>

		<property name="acquireIncrement">
			<value>${c3p0.acquireIncrement}</value>
		</property>
		<property name="initialPoolSize">
			<value>${c3p0.initialPoolSize}</value>
		</property>
		<property name="minPoolSize">
			<value>${c3p0.minPoolSize}</value>
		</property>
		<property name="maxPoolSize">
			<value>${c3p0.maxPoolSize}</value>
		</property>
		<property name="maxIdleTime">
			<value>${c3p0.maxIdleTime}</value>
		</property>
		<property name="unreturnedConnectionTimeout">
			<value>${c3p0.unreturnedConnectionTimeout}</value>
		</property>
		<property name="debugUnreturnedConnectionStackTraces">
			<value>${c3p0.debugUnreturnedConnectionStackTraces}</value>
		</property>
		<property name="idleConnectionTestPeriod">
			<value>${c3p0.idleConnectionTestPeriod}</value>
		</property>
		<property name="maxStatements">
			<value>${c3p0.maxStatements}</value>
		</property>
		<property name="numHelperThreads">
			<value>${c3p0.numHelperThreads}</value>
		</property>
	</bean>

	<!-- Hibernate配置 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.validator.apply_to_ddl">false</prop>
				<prop key="hibernate.validator.autoregister_listeners">false</prop>
				<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> --> <!-- 自动建表 -->
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.query.substitutions">true 1, false 0</prop>

				<!-- =============== 二级缓存设置 =================== -->
				<prop key= "org.hibernate.cacheable">false</prop>
				<prop key="hibernate.cache.use_second_level_cache">false</prop>
				<prop key="hibernate.cache.use_query_cache">false</prop>
				<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
				<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
			</props>
		</property>
		<property name="packagesToScan" value="ipebg.*" />
	</bean>


	<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- 使用AspectJ方式配置AOP -->
	<aop:aspectj-autoproxy proxy-target-class="true" />

	<aop:config />
	<aop:config proxy-target-class="true">
		<aop:advisor pointcut="execution(* ipebg.mzk.provider.system.service..*.*(..))" advice-ref="transactionAdvice" /> <!-- 配置哪些类的哪些方法参与事务 -->
	</aop:config>



	<tx:annotation-driven transaction-manager="txManager" />

	<!-- 配置事务传播特性 -->
	<tx:advice id="transactionAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="del*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="do*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="get*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="search*" read-only="true" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
</beans>